﻿
function popwindows1(dialogobj) {
    var dialog = {
        dialog_mask: 'dialog_bg',
        dialog_id: 'dialog_id',
        dialog_close: 'dialog_close',
        init: function () {
            $.extend(dialog, dialogobj);
            dialog.checkId();
            dialog.createdialog();
        },
        checkId: function () {
            if ($("#" + dialog.dialog_id).length > 0) {
                $("#" + dialog.dialog_mask, "#" + dialog.dialog_id).remove();
            }
        },
        createdialog: function () {
            var _dialoghtml = [];
            _dialoghtml.push('<div id="dialog_bg" style="background:#000;width:100%;height:100%;position:fixed; _position:absolute; top:0;left:0; z-index: 20000;filter:alpha(opacity=50);-moz-opacity:0.5;-khtml-opacity: 0.5;opacity: 0.5; "></div>');
            _dialoghtml.push('<div id="' + dialog.dialog_id + '" style="background:#fff;position: absolute; z-index: 20001;border:1px solid #ccc;">');
            _dialoghtml.push('<div style="background:#d5d5d5;height:24px;line-height:24px;padding:0 5px;"><span style="width:30px;float:right;cursor:pointer" title=' + lang.close + ' id="dialog_close">' + lang.close + '</span><span>');
            _dialoghtml.push(dialog.title);
            _dialoghtml.push('</span></div><div>');
            _dialoghtml.push(dialog.html);
            _dialoghtml.push('</div><div style="height:1px;clear:both;"></div></div>');
            $('body').append(_dialoghtml.join(''));

            $('#' + dialog.dialog_close).bind('click', function () {
                dialog.close();
            });

            $("#" + dialog.dialog_id).css({ width: dialog.width + "px" });
            if (dialog.height) { $("#" + dialog.dialog_id).css({ height: dialog.height + "px" }); }

            $("#" + dialog.dialog_id).css({ left: ($(window).width() - $("#" + dialog.dialog_id).width()) / 2 + $(window).scrollLeft() + "px",
                top: ($(window).height() - $("#" + dialog.dialog_id).height()) / 2 + $(window).scrollTop() + "px"
            });
        },
        close: function () {
            $("#" + dialog.dialog_mask + ",#" + dialog.dialog_id).remove();
        }
    }
    dialog.init();
    return dialog;
}
//#endregion

var dialog_opendiv;
function searchOrgType(inputId) {
    $('#' + inputId).val('');
    $('#syfwValue').val('');
    var hideInputId = "syfwValue";
    var _html = [];
    _html.push('<div>')
    _html.push('<div style="overflow:auto;height:390px;">')
    _html.push('<div id="tree">');
    _html.push('</div>');
    _html.push('</div>');
    _html.push('</div>');
    dialog_opendiv = popwindows1({ html: _html.join(''), title: lang.shared_scope, width: 500, height: 420 });
    $('#tree').tree({ 'checkbox': false, onDblClick: function (node) { if (!isexist(inputId, hideInputId, node.id)) { $('#' + inputId).val($('#' + inputId).val() + " " + node.text); $('#' + hideInputId).val(node.id); } } });
    getorgtreelist();
}

//#region 加载菜单数据
function getorgtreelist() {
    $.ajaxHandler({
        url: App_Config.TadongUrl + "/AjaxMappingHandler.aspx",
        urlType: "QueryOrganizeList",
        success: function (data) {
            if (data && data.length > 0) {
                var _data = [];
                for (var i = 0; i < data.length; i++) {
                   if (data[i].PARENTID == '0') {
                        var obj = {};
                        obj.id = data[i].ORGANIZATION_ID;
                        obj.text = data[i].ORGANIZATION_NAME;
                        getsubtree(data, data[i].ORGANIZATION_ID, obj);
                        _data.push(obj);
                   }
                }
                $('#tree').tree('loadData', _data);
                idstr = "syfwValue";
            }

        }
    });

    function getsubtree(_d, _pid, obj2) {
        if (_d && _d.length > 0) {
            var _sdata = [];
            for (var i = 0; i < _d.length; i++) {
                if (_d[i].PARENTID == _pid) {
                    var obj = {};
                    obj.id = _d[i].ORGANIZATION_ID;
                    obj.text = _d[i].ORGANIZATION_NAME;
                    _sdata.push(obj);
                }
            }
            obj2.children = _sdata;
            if (_sdata.length > 0) {
                for (var j = 0; j < _sdata.length; j++) {
                    getsubtree(_d, _sdata[j].id, _sdata[j]);
                }
            }
        }
    }
}
function isexist(inputId, hideid, val) {
    var _vals = $('#' + hideid).val();
    if (_vals == '') {
        $('#' + hideid).val($('#' + hideid).val() + ',' + val);
        return false;
    }
    else {
        var _valarr = _vals.split(',');
        if ($.inArray('' + val, _valarr) > -1) {
            return true;
        }
        else {
            $('#' + hideid).val($('#' + hideid).val() + ',' + val);
            return false;
        }
    }
}





